<?php
namespace Admin\Controller;
use Think\Controller;
class AuthController extends Controller {
    public function login(){
    	layout(false);
 	$this->display();     
}
	public function do_login(){
		 $rules=array(
		     array('username','require','用户名必须！'), 
		     array('password','require','密码必须！'), 
		     );
		$admin_model = M("admin"); // 实例化User对象
		if (!$admin_model->validate($rules)->create()){
		     // 如果创建失败 表示验证没有通过 输出错误提示信息
		     $this->error($admin_model->getError());
		}else{
				$username=I('post.username');
				$password=md5(I('post.password'));
				if($admin=M('admin')->where(array(
					'username'=>$username,
					'password'=>$password
					))->find()){
						$_SESSION['admin_is_login']=true;
						$_SESSION['admin_name']= $admin['username'];
						$this->success('登录成功',U('admin/index/index'));
				}else{
					$this->error('账户名密码不正确');
				}
			}
		
	}
	public function logout(){
		session_destroy();
		$this->success('退出成功',U('admin/auth/login'));
	}
}